﻿namespace EyeOpen.BomberMan
{
	using System.Collections;
	using System.Collections.Generic;

	public class MapEnumerator : IEnumerator<ItemType>
	{
		private readonly Map map;
		private int x = -1;
		private int y;

		public MapEnumerator(Map map)
		{
			this.map = map;
		}

		public ItemType Current
		{
			get { return map[x, y]; }
		}

		object IEnumerator.Current
		{
			get { return Current; }
		}

		public bool MoveNext()
		{
			x++;

			if (x == map.Size.Width)
			{
				var isEnd = (x >= map.Size.Width - 1) && (y >= map.Size.Height - 1);
				
				if (isEnd)
				{
					return false;
				}

				x = 0;
				y++;
			}

			return true;
		}

		public void Reset()
		{
			x = -1;
			y = 0;
		}

		public void Dispose()
		{
		}
	}
}